package com.zdd.chap2thymeleaf.controller;

import com.zdd.chap2thymeleaf.entity.User;
import jakarta.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Controller
public class ThymeleafController {
    @GetMapping("/index")
    public String index(Model model){
        model.addAttribute("username","admin");
        model.addAttribute("text1","Hello Word");
        model.addAttribute("text2","<h1>Hello Word</h1>");
        model.addAttribute("gender","女");
        model.addAttribute("city","北京");
        User user1=new User(1,"李白","123");
        User user2=new User(2,"杜甫","123");
        List<User> users=new ArrayList<>();
        users.add(user1);
        users.add(user2);
        model.addAttribute("users",users);

        //为html标签设置属性值
        model.addAttribute("name","telepone");
        model.addAttribute("user",user1);
        model.addAttribute("score",85);
        model.addAttribute("password","123");
        return "index";
    }

    @GetMapping("/test")
    public String test(Model model, HttpSession session){
        List<String> list=new ArrayList<String>();
        list.add("北京");
        list.add("上海");
        list.add("广州");
        list.add("深圳");
        model.addAttribute("list",list);
        model.addAttribute("date",new Date());
        model.addAttribute("salary",20000.168);
        model.addAttribute("word","helloWorld");
        return "test";
    }
}
